package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.manager.HarmlessManager;
import com.jiantong.work.model.Harmless;
import com.jiantong.work.service.HarmlessWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by niufei on 2017/3/27.
 *
 */
@Slf4j
@Service
@RpcProvider
public class HarmlessWriteServiceImpl implements HarmlessWriteService{

    private final HarmlessManager harmlessManager;

    @Autowired
    public HarmlessWriteServiceImpl(HarmlessManager harmlessManager) {
        this.harmlessManager = harmlessManager;
    }

    @Override
    public Response<Map<String , Object>> updateHarmless(Harmless harmless, Integer toStatus) {
        try{
            return Response.ok(harmlessManager.updateHarmless(harmless,toStatus));
        }catch (Exception e){
            log.error("failed to update harmless error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("harmless.update.failed");
        }
    }

    @Override
    public Long createHarmless(Harmless harmless) {
        return null;
    }

    @Override
    public Boolean update(Harmless harmless) {
        return harmlessManager.update(harmless);
    }
}
